package com.gnote.repair.controller;

import com.alibaba.fastjson.JSON;
import com.gnote.repair.domain.SysRole;
import com.gnote.repair.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnote
 * @since 2025/2/25 08:55
 */
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {
    private final SysRoleService sysRoleService;

    @GetMapping("/abc")
    @PreAuthorize("hasAnyAuthority('sys:test:abc')")
    public String test() {
        return "test";
    }

    @GetMapping("/getUser")
    @PreAuthorize("hasAnyAuthority('sys:test:getUser')")
    public String getUser() {
        List<SysRole> rolesByUserId = sysRoleService.getRolesByUserId(1L);
        return JSON.toJSONString(rolesByUserId);
    }
}
